package reflect;

import java.lang.reflect.Field;

public class ReflectDemo11 {
    public static void main(String[] args) throws Exception{
        Class cls=Class.forName("reflect.Teacher");
        Object obj=cls.newInstance();
//        Field field=cls.getField("gender");//NoSuchFieldException
//        Field field=cls.getDeclaredField("gender");//IllegalAccessException
        Field field=cls.getDeclaredField("gender");
        field.setAccessible(true);
        field.set(obj,'男');
        System.out.println(obj);
    }
}
